﻿<!--#Include file = "includes/SqlHelper.asp"-->
<!--#Include file = "includes/database.asp"-->
<!--#Include file = "includes/function.asp"-->
<!--#Include file = "includes/language.asp"-->
<!--#Include file = "includes/browser_page_encoding_inc.asp"-->
<!--#Include file = "includes/global_varaiable.asp"-->

<%If Session("StaffID") = "" then Response.Redirect("login.asp")%>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language=JavaScript src="js/change.js">
</script>

<script type="text/jscript">
</script>

<link href="css/default.css" rel="stylesheet" type="text/css" />
</head>

<body>

<b>

<%

function fixL(s)
		s = replace(s,"'","")
s= replace(s,"#'","")
fixL = replace(s,";'","")
end function
	giochieuID = fixL(Request.Form("GiochieuID"))
	rapID = fixL(Request.Form("RapID"))
	ngaychieu = fixL(Request.Form("Ngaychieu"))
	soghechon = fixL(Request.Form("Soghechon"))
	gia = fixL(Request.Form("Gia"))
	filmID = fixL(Request.Form("FilmID"))
	isOK = true
	
	StaffID = Session("StaffID")
	
	soghechon = Replace(soghechon, " ", "")
	
	ghechons = Split(soghechon, ",")
	soluongVe = UBound(ghechons) + 1
	
	thanhtien = CInt(soluongVe) * CDbl(gia)
	
	maxY = 0

		ghechons = Split(soghechon, ",")
		length = UBound(ghechons)
	
		if length >= 0 then
			'check xem co ai da bán ve o cho do chua
			set rs = CreateObject("ADODB.Recordset")
			for i = 0 to length
				toadoghe = Split(ghechons(i), "_")
				sogheX = toadoghe(0)
				sogheY = toadoghe(1)
				strSQL = " SELECT TOP 1 Status FROM BANVE WHERE RoomID = " & EncodeSql(rapID) & " AND SessionID = " & EncodeSql(giochieuID) & " AND convert(char(10), DayShow, 101) = '" & EncodeSql(ngaychieu) & "' AND SeatX = " & sogheX & " AND SeatY = " & sogheY
				rs.Open strSQL, adoCon
				If rs("Status") = 3 then
					isOK = false
				end if
				rs.Close				
			next
							
		end if
		
		if isOK = false then
			Response.Write(vbCrLf & "<script language=""JavaScript"">")
			Response.Write(vbCrLf & "alert('Ghế chọn đã bị bán, vui lòng kiểm tra lại!');")
			Response.Write(vbCrLf & "window.location = 'default.asp?Ngaychieu=" & ngaychieu & "&GiochieuID=" & giochieuID & "&RapID=" & rapID & "&FilmID=" & filmID & "'")
			Response.Write(vbCrLf & "</script>")
				
		else
			
			strSQL = " UPDATE BANVE SET StaffID= '" & StaffID & "', Status = 3"
					
			strSQL = strSQL & " WHERE RoomID = " & EncodeSql(rapID) & " AND SessionID = " & EncodeSql(giochieuID) & " AND convert(char(10), DayShow, 101) = '" & EncodeSql(ngaychieu) & "' AND ( "

			for i = 0 to length
				toadoghe = Split(ghechons(i), "_")
				sogheX = toadoghe(0)
				sogheY = toadoghe(1)
				if i > 0 then
					strSQL = strSQL & " OR "
				end if
					strSQL = strSQL & " SeatX = " & sogheX & " AND SeatY = " & sogheY
				next

				strSQL = strSQL & " ) "

				'Response.Write "[[" & strSQL & "]]"
				set rs= adoCon.Execute(strSQL)
				
		end if
		set rs = Nothing

			Response.Write(vbCrLf & "<script language=""JavaScript"">")
			Response.Write(vbCrLf & "alert('Tổng số tiền là: " & thanhtien & "');")
			Response.Write(vbCrLf & "window.location = 'default.asp?Ngaychieu=" & ngaychieu & "&GiochieuID=" & giochieuID & "&RapID=" & rapID & "&FilmID=" & filmID & "'")
			Response.Write(vbCrLf & "</script>")
		

%>
